import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    count: 0
  },
  mutations: {
    add: (state, step) => {
      state.count += step
    },
    sub: (state, step) => {
      state.count -= step
    }
  },
  // 异步操作必须在actions中操作
  actions: {
    addAsync: (context, step) => {
      setTimeout(() => {
        context.commit('add', step)
      }, 1000)
    }
  },
  getters: {
    showNum: state => {
      return state.count
    }
  },
  modules: {
  }
})
